﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FJERP.BLL;
using System.Data;

namespace FJERP.Handler
{
    /// <summary>
    /// Product 的摘要说明
    /// </summary>
    public class Product : IHttpHandler
    {
        DocumentBLL bll = new DocumentBLL();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"].ToString();
            System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(action);
            if (methodInfo != null)
            {
                methodInfo.Invoke(this, new object[] { context });
            }
        }
        public void brand(HttpContext context)
        {
            string Product_Name = context.Request["Product_Name"];
            DataTable data = bll.Product_Sel(Product_Name);
            List<FJERP.Model.Product> list = new List<FJERP.Model.Product>();
            foreach (DataRow item in data.Rows)
            {
                FJERP.Model.Product P = new FJERP.Model.Product();
                P.Product_Id = Convert.ToInt32(item["Product_Id"]);
                P.Product_Barcode = item["Product_Barcode"].ToString();
                P.Product_Bprid = Convert.ToDecimal(item["Product_Bprid"]);
                P.Product_frim = item["Product_frim"].ToString();
                P.Product_Modelspe = item["Product_Modelspe"].ToString();
                P.Product_Name = item["Product_Name"].ToString();
                P.Product_Price = Convert.ToDecimal(item["Product_Price"]);
                P.Product_Remark = item["Product_Remark"].ToString();
                P.Product_Type_Name = item["Product_Type_Name"].ToString();
                P.Product_Unit_Id = item["Product_Unit_Id"].ToString();
                list.Add(P);
            }
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Document(HttpContext context)
        {
            FJERP.Model.Document P = new FJERP.Model.Document();
            P.Document_Date = Convert.ToDateTime(context.Request["Document_Date"]);
            P.Document_Remark = context.Request["Document_Remark"];
            P.Document_Type_Name = context.Request["Document_Type_Name"];
            P.WareHose_Id = Convert.ToInt32(context.Request["WareHose_Id"]);
            P.Employee_Id = Convert.ToInt32(context.Request["Employee_Id"]);
            P.Document_num = context.Request["Document_num"];
            string xml = context.Server.UrlDecode(context.Request.Form["xml"].ToString());
            context.Response.Write(bll.Document_Add(P, xml));
        }
        public void Document_show(HttpContext context)
        {
            string Document_Type_Name = context.Request["Document_Type_Name"].ToString();
            List<FJERP.Model.Document> list = bll.Document_Show(Document_Type_Name);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Document_Pro(HttpContext context)
        {
            string Document_Type_Name = context.Request["Document_Type_Name"].ToString();
            List<FJERP.Model.Document_Mate> list = bll.Document_Show_Pro(Document_Type_Name);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public void Document_Show_List(HttpContext context)
        {
            string Document_Type_Name = context.Request["Document_Type_Name"].ToString();
            List<FJERP.Model.Document> list = bll.Document_Show_List(Document_Type_Name);
            context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(list));
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}